package com.tij.rtti.typeinfo.pet;

import java.util.*;

/**
 * @ClassName:
 * @author:
 * @Description: TODO
 * data:2024/10/6 21:17
 * @since
 **/
public abstract class PetCreator {
    private Random rand = new Random(47);

    // the List of  the different types of Pet to create
    public abstract List<Class<? extends  Pet>> types();

    public Pet randomPet(){
        int n = rand.nextInt(types().size());
        try {
            return types().get(n).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public Pet[] createArray(int size){
        Pet[] result =  new Pet[size];
        for(int i =0;i<size ; i++){
            result[i] = randomPet();
        }
        return result;
    }

    public ArrayList<Pet> arrayList(int size){
        ArrayList<Pet> result  = new ArrayList<>();
        Collections.addAll(result,createArray(size));
        return result;
    }

}
